<template>
	<view class="cashoutlist">
		<view class="listWrapper">
			
			<view v-for="item in dataList" class="item">
				<view class="mark">{{item.Mark}}</view>
				<view class="time">{{item.AddTimeStr}}</view>
				<view class="balance" :class="{positive:item.pm=='+'}">{{item.pm}}{{(item.Balance/100).toFixed(2)}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import http from '../../common/http.js';
	import common from '../../common/common.js';
	export default {
		data() {
			return {
				lastid:0,
				noMore:false,
				isLoadingMore:false,
				dataList:[],
				storeid:''
			}
		},
		onLoad(options) {
			this.storeid = options.storeid
			this.refreshData()
		},
		onPullDownRefresh() {
			this.isLoadingMore = false
			this.lastid = 0
			this.refreshData()
		},
		onReachBottom() {
			if (this.noMore == false) {
				this.isLoadingMore = true
				this.refreshData()
			}
		},
		methods: {
			refreshData(){
				var self = this
				http.get("/store/bill", {"lastid":self.lastid, "storeid":this.storeid}, (res)=>{
					uni.stopPullDownRefresh()
					var billList = res
					for (var i=0;i<billList.length;i++) {
						var item = billList[i]
						item["AddTimeStr"] = common.formatTime(item.AddTime)
						item["pm"] = item.Balance>=0? "+":""
						
					}
					if (billList.length > 0){
						self.lastid = billList[billList.length-1]["Id"]
					}
					
					if (self.isLoadingMore) {
						self.dataList = self.dataList.concat(billList)
					}else{
						self.dataList = billList
					}
					
					if (billList.length == 0) {
						self.noMore = true
					}else{
						self.noMore = false
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #f3f3f2;
	}
	.cashoutlist {
		color: #333333;
		font-size: 14px;
	}
	.item-header {
		display: flex;
		justify-content: space-between;
		border-bottom: 1px solid #f6f6f6;
		height: 30px;
		line-height: 25px;
	}
	.listWrapper {
		background-color: #f6f6f6;
	}
	.item {
		padding: 10px 10px;
		box-sizing: border-box;
		background-color: white;
		margin-bottom: 10px;
		position: relative;
		min-height: 60px;
	}
	.item-title {
		font-size: 14px;
		color: #333333;
		font-weight: 500;
	}
	.mark {
		font-size: 15px;
		max-width: 70%;
	}
	.time {
		font-size: 14px;
		color: #999999;
	}
	.balance {
		color: #333333;
		font-size: 18px;
		right: 15px;
		font-weight: 400;
		top: 15px;
		position: absolute;
	}
	.positive {
		color: red;
	}
</style>
